package com.automation.ljf.repository.impl.mapper;

import com.automation.ljf.domain.po.CasePO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 操作mf_case表
 *
 * @author lijiefeng
 * @since 2021/8/25
 */
@Mapper
public interface CaseMapper {

    /**
     * 根据测试用例id查询测试用例
     * @param caseId    用例id
     * @return  CasePO
     */
    @Select({"<script>" +
            "select id, case_id, case_url, case_name, case_detail, adm_user_id, create_time, update_time" +
            " from mf_case where case_id = #{caseId} and is_delete = false" +
            "</script>"})
    CasePO selectCaseByCaseId(@Param("caseId") String caseId);

    /**
     * 创建测试用例
     * @param casePO    用例PO实体
     * @return  Integer
     */
    @Insert({"<script>" +
            "insert into mf_case " +
            "(id, case_id, case_url, case_name, case_detail, adm_user_id, create_time, update_time) " +
            "values(#{id}, #{caseId}, #{caseUrl}, #{caseName}, #{caseDetail}, #{admUserId}, #{createTime}, #{updateTime})" +
            "</script>"})
    Integer insertCase(CasePO casePO);


    /**
     * 查询所有测试用例
     * @param admUserId 用户id
     * @return  List
     */
    @Select("select id, case_id, case_url, case_name, case_detail, adm_user_id, create_time, update_time" +
            " from mf_case where adm_user_id = #{admUserId} and is_delete = false")
    List<CasePO> selectCaseByPage(String admUserId);

    /**
     * 修改用例信息
     * @param casePO    用例实体
     * @return  Integer
     */
    @Update("update mf_case set case_name = #{cp.caseName}, case_url = #{cp.caseUrl}, case_detail = #{cp.caseDetail}, update_time = #{cp.updateTime} " +
            "where case_id = #{cp.caseId}")
    Integer updateCaseByCaseId(@Param("cp") CasePO casePO);


    /**
     * 批量逻辑删除测试用例
     * @param casePOS   用例PO实体数组
     * @return  Integer
     */
    @Update("<script>" +
            "update mf_case set is_delete = true " +
            "<foreach collection='list' item='item' index='index' separator=','>" +
            "where case_id = #{item.caseId}" +
            "</foreach>" +
            "</script>")
    Integer deleteCaseByCaseId(@Param("list") List<CasePO> casePOS);

}
